﻿using System.Collections.Generic;
using System.Linq;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoL.EntityLib.StatusEffects.Cirno;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeXelnagaArcaneDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            CardConfig config = GetCardDefaultConfig();

            config.Rarity = Rarity.Uncommon;
            config.Type = CardType.Skill;
            config.TargetType = TargetType.Nobody;

            config.Colors = new List<ManaColor>() { ManaColor.Blue,ManaColor.Green };
            config.Cost = new ManaGroup() { Blue = 1, Green = 1 };
            config.IsXCost = true;

            config.Mana = new ManaGroup() { Philosophy = 1 };

            config.Keywords = Keyword.Exile;
            config.UpgradedKeywords = Keyword.Exile;

            config.Value1 = 1;
            config.Value2 = 12;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);
            return config;
        }
    }

    /// <summary>
    /// 萨尔那加的智慧
    /// 
    /// </summary>
    [EntityLogic(typeof(ProbeXelnagaArcaneDef))]
    public sealed class ProbeXelnagaArcane : ProbeCard
    {
        public int NeedManaCost => IsUpgraded ? 4 : 6;

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            var drawCount = SynergyAmount(consumingMana, ManaColor.Blue);
            var manaGain = SynergyAmount(consumingMana, ManaColor.Green);
            var canAddHandGain = SynergyAmount(consumingMana, ManaColor.Any) >= NeedManaCost;

            if(canAddHandGain)
            {
                yield return BuffAction<MaxHandSe>();
            }

            yield return new DrawManyCardAction(drawCount);
            yield return new GainManaAction(new ManaGroup() { Philosophy = manaGain });

        }
    }
}
